package com.example.bluploader;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.example.bluploader.utils.PermissionsHelper;

public class MainActivity extends AppCompatActivity {
    protected WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        PermissionsHelper.requestPermissions(this);

        webView = (WebView) findViewById(R.id.webview);
        webView.loadUrl("http://192.168.10.149:5173/");
//        webView.loadUrl("file:///android_asset/react-web/dist/index.html");//加载url
        webView.setWebViewClient(new WebViewClient());// 防止调用外部浏览器
        webView.setWebChromeClient(new WebChromeClient());// alert弹窗需要
        webView.addJavascriptInterface(new WebAppInterface(this), "demoApp");
        WebView.setWebContentsDebuggingEnabled(true);
        WebSettings webViewSetting = webView.getSettings();
        webViewSetting.setJavaScriptCanOpenWindowsAutomatically(true);//设置js可以直接打开窗口，如window.open()，默认为false
        webViewSetting.setJavaScriptEnabled(true);//是否允许执行js，默认为false。设置true时，会提醒可能造成XSS漏洞
        webViewSetting.setSupportZoom(true);//是否可以缩放，默认true
        webViewSetting.setBuiltInZoomControls(true);//是否显示缩放按钮，默认false
        webViewSetting.setUseWideViewPort(true);//设置此属性，可任意比例缩放。大视图模式
        webViewSetting.setLoadWithOverviewMode(true);//和setUseWideViewPort(true)一起解决网页自适应问题
        webViewSetting.setDomStorageEnabled(true);//DOM Storage
        webViewSetting.setAllowFileAccessFromFileURLs(true); // 跨域
        webViewSetting.setSupportZoom(false);//设定支持缩放

    }

    /**
     * 动态权限回调事件
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        Log.i("dsh", "onRequestPermissionsResult: ");
        PermissionsHelper.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

}